package net.huashitong.synthetical.gradePoint.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.core.filter.BaseFilter;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.synthetical.gradePoint.entity.GradePoint;
import net.huashitong.synthetical.gradePoint.filter.GradePointFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class GradePointDao extends StringDao<GradePoint> {

    public List<GradePoint> queryByFilter(GradePointFilter filter){
        GenericQuery query = createQuery("obj");
        if(StringUtils.isNotBlank(filter.getCheckType())){
            query.append(" and obj.checkType =:checkType").setParam("checkType", filter.getCheckType());
        }
        if(StringUtils.isNotBlank(filter.getCheckObject())){
            query.append(" and obj.checkObject like:checkObject").setParam("checkObject",
                    StringUtils.getLikewords(filter.getCheckObject()));
        }
        if(StringUtils.isNotBlank(filter.getTaskName())){
            query.append(" and obj.taskName like:taskName").setParam("taskName",
                    StringUtils.getLikewords(filter.getTaskName()));
        }
        if(StringUtils.isNotBlank(filter.getTaskId())){
            query.append(" and obj.taskId =:taskId").setParam("taskId", filter.getTaskId());
        }
        if(StringUtils.isNotBlank(filter.getSources())){
            query.append(" and obj.sources =:sources").setParam("sources", filter.getSources());
        }
        if(StringUtils.isNotBlank(filter.getTaskContent())){
            query.append(" and obj.taskContent like:taskContent").setParam("taskContent",
                    StringUtils.getLikewords(filter.getTaskContent()));
        }

        return query.listResult(filter);
    }
}
